/**
*   \file   aabbaabb.h
*   \author Dave Reid
*   \brief  Header file for checking if two AABB's overlap
*/
#ifndef __EAGL_INTERSECT_AABBAABB_H_
#define __EAGL_INTERSECT_AABBAABB_H_

#include "../types.h"

namespace eagl
{

inline bool intersect_aabbaabb(const vec3 &aabb0Extents, const vec3 &aabb0Position,
                               const vec3 &aabb1Extents, const vec3 &aabb1Position)
{
    vec3 min0 = aabb0Position - aabb0Extents;
    vec3 max0 = aabb0Position + aabb0Extents;
    vec3 min1 = aabb1Position - aabb1Extents;
    vec3 max1 = aabb1Position + aabb1Extents;

    // X slice.
    if (min0.x > max1.x) return false;
    if (max0.x < min1.x) return false;

    // Y slice.
    if (min0.y > max1.y) return false;
    if (max0.y < min1.y) return false;

    // Z slice.
    if (min0.z > max1.z) return false;
    if (max0.z < min1.z) return false;

    return true;
}

}

#endif  // __EAGL_INTERSECT_AABBAABB_H_